﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using TelecoSystems.Infrastructure;
using TelecoSystems.Web;
using System.Collections.Generic;
using TelecoSystems.Modules.Administration.Views;

namespace TelecoSystems.Modules.Administration
{
    public class AdministrationModule : IModule
    {
        private readonly IRegionManager regionManager;
        private readonly IUnityContainer unityContainer;
        private const string MODULE_NAME = "Administration";

        public AdministrationModule(IRegionManager _regionManager, IUnityContainer _unityContainer)
        {
            regionManager = _regionManager;
            unityContainer = _unityContainer;
        }

        public void Initialize()
        {
            unityContainer.RegisterType<AuthenticationContext>(new InjectionConstructor());
            unityContainer.RegisterType<UserRegistrationContext>(new InjectionConstructor());
            
            IRegion region = regionManager.Regions[RegionNames.MainRegion];
            AdministrationModuleView cmView = this.unityContainer.Resolve<AdministrationModuleView>();
            region.Add(cmView, cmView.GetType().Name);
            region.Activate(cmView);

            region = regionManager.Regions[MODULE_NAME + RegionNames.ModuleRegion];
            regionManager.RegisterViewWithRegion(MODULE_NAME + RegionNames.ModuleRegion, () => this.unityContainer.Resolve<UsersView>());
        }

    }
}
